<template>
  <article class="page">
    <headerbar>支部信息</headerbar>
    <section class="frame-content-sub no-bg">

      <section class="inner-content pdv-9 pdh-4">

        <div class="input-row-wrap" @click="selectDuration()">
          <div class="name">支部类型：</div>
          <input v-model="typeLabel" type="text" readonly placeholder="请选择支部类型">
        </div>

        <div class="input-row-wrap" @click="showTimePicker()">
          <div class="name">上次换届时间：</div>
          <input v-model="form.upChangeTime" placeholder="请选择上次换届时间" readonly type="text"></input>
        </div>

        <div class="input-row-wrap">
          <div class="mgt-5 color-tip mgb-1"><i class="required color-red">严禁上传或录入涉密内容</i></div>
          <div class="name">封面：</div>
          <section class="upload-wrap">
            <cube-upload ref="upload"
                         action=""
                         accept="image/*"
                         :simultaneous-uploads="1"
                         @files-added="uploadFile"
                         :max="1"
            />
          </section>
        </div>



        <div class="pdv-6"></div>

        <div @click="save($event)" v-preventReClick="1000" class="default-block-btn">提交</div>

        <div class="pdv-5"></div>
      </section>

    </section>
  </article>
</template>

<script>
  import moment from 'moment'

  export default {
    name: 'learningExperiencesAdd',
    data () {
      return {
        form: {
          orgId: '',
          annexInfo: '',
          spaceType: '1',
          cover: '',
          orgType: '',
          upChangeTime: ''
        },
        attachmentList: {},
        feedTypes: [],
        typeLabel: '',
        datePicker: null,
        isSubmit: true
      }
    },
    created () {
      this.form.orgId = this.$route.params.id
      console.log("form---------", this.form.orgId)
      this.findDictList()
    },
    methods: {
      uploadFile (file) {
        this.isSubmit = false
        let uploadFile = file[0]
        let formData = new FormData()
        formData.append('file', uploadFile)
        this.fetchService.o_upload(formData).then((res) => {
          if (res.code !== 0) {
            return this.tools.tip(res.message)
          }
          let ret = res.data
          let data = {
            fileid: ret.fileId,
            filename: uploadFile.name
          }
          this.attachmentList = data
          this.isSubmit =true
        })
      },
      save (e) {
        if (e.target.disabled) {
          return false
        }
        if(!this.isSubmit){
          return this.tools.tip("文件上传中",1500)
        }
        this.form.cover = this.attachmentList.fileid
        console.log('---------------this.form.annexInfo=', this.form.annexInfo)
        this.fetchService.saveOrgInfoExt(this.form).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message)
          }
          this.tools.tip('提交成功')
          this.tools.back()
        })
      },
      // 会议时间格式：2019-12-06 21:48:00 精确到分
      showTimePicker () {
        if (!this.datePicker) {
          let me = this
          let nowYear = new Date().getFullYear()
          this.datePicker = this.$createDatePicker({
            min: new Date(2008),
            max: new Date(),
            value: new Date(),
            onSelect: (selectedTime, selectedText, formatedTime) => {
              this.form.upChangeTime = this.honorTimeValue = moment(selectedTime).format('YYYY-MM-DD')
              console.log('----------------honorTime=', this.honorTime)
            }
          })
        }
        this.datePicker.show()
      },
      // 选择类型
      selectDuration () {
        this.$createActionSheet({
          active: 10,
          data: this.feedTypes,
          onSelect: (item, index) => {
            this.typeLabel = item.content
            this.form.orgType = item.scope
            this.$forceUpdate()
          },
          onCancel: () => {
          }
        }).show()
      },
      findDictList () {
        this.feedTypes = []
        let data = {
          loginId: '3750',
          dictType: 'org_info_type',
          excludeType: this.excludeType
        }
        this.fetchService.findDictList(data).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message)
          }
          res.data.map((v) => {
            let types = {
              scope: v.value,
              content: v.label
            }
            this.feedTypes.push(types)
          })
          console.log('-------------feedTypes=', this.feedTypes)
        })
      }
    }
  }
</script>

<style scoped>

</style>
